package org.stvd.common.freemarker.support;

import java.io.IOException;

import org.springframework.util.CollectionUtils;
import org.stvd.common.Consts;
import org.stvd.common.freemarker.method.UserDetailSession;

import freemarker.template.SimpleHash;
import freemarker.template.TemplateException;

public class FreeMarkerConfigurerEx extends org.stvd.core.web.freemarker.support.FreeMarkerConfigurerEx {

    @Override
    public void afterPropertiesSet() throws IOException, TemplateException {
        super.afterPropertiesSet();

        // 系统名称
        this.getConfiguration().setSharedVariable("SystemName", Consts.SYSTEM_NAME);
        // UserDetail
        this.getConfiguration().setSharedVariable("UserDetailSession", new UserDetailSession());
        // 加载系统的码表
        if (!CollectionUtils.isEmpty(Consts.GLOBAL_MAP)) {
            this.getConfiguration().setAllSharedVariables(
                    new SimpleHash(Consts.GLOBAL_MAP, this.getConfiguration().getObjectWrapper()));
        }
    }
}
